from common import *

default_data = {'sensitivity':1.0, 'axis':0}

def setup(data = default_data):
    import wx
    dlg = wx.TextEntryDialog(
        None, 'Sensitivity',
        'Configure Process', str(data['sensitivity']))
    if dlg.ShowModal() == wx.ID_OK:
       try:
            data['sensitivity'] = eval(dlg.GetValue())
       except:
           pass
    dlg.Destroy()

    dlg = wx.TextEntryDialog(
        None, 'Axis (0=x,1=y)',
        'Configure Process', str(data['axis']))
    if dlg.ShowModal() == wx.ID_OK:
        try:
            data['axis'] = eval(dlg.GetValue())
        except:
            pass
    dlg.Destroy()
    return data

def InteractiveJoystickCtrlFunc(in0,in1,out0 , data = default_data):
    (min,max,points) = in0()
    while True:
        cmd = in1()
        diff = max - min

        if cmd == '+':
            min+=.25*diff*data['sensitivity']
            max-=.25*diff*data['sensitivity']
        elif cmd == '-':
            min-=.5*diff*data['sensitivity']
            max+=.5*diff*data['sensitivity']
        elif cmd == 'UP' and data['axis'] == 1:
            min-=diff*data['sensitivity']
            max-=diff*data['sensitivity']
        elif cmd == 'DOWN' and data['axis'] == 1:
            min+=diff*data['sensitivity']
            max+=diff*data['sensitivity']
        elif cmd == 'LEFT' and data['axis'] == 0:
            min-=diff*data['sensitivity']
            max-=diff*data['sensitivity']
        elif cmd == 'RIGHT' and data['axis'] == 0:
            min+=diff*data['sensitivity']
            max+=diff*data['sensitivity']

        out0((min,max,points))

